<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        body {
            height: 4000px;
        }

        #b1 {
            display: none;
            position: fixed;
            bottom: 0;
            width: 300px;
            height: 100px;
            right: 0;
        }

        .m1 {
            display: block !important;

        }
    </style>
</head>

<body>
    <button id="b1">top</button>
    <script>
        window.onscroll = function () {
            // console.log()
            if (scrollY >= 1000) {
                b1.style.display = "block"
                // b1.className = "m1"
            }
        }
        let a;
        b1.onclick = (function () {
            // console.log("asd")
            clearInterval(a)
            a = setInterval(() => {
                if (scrollY > 0) {
                    window.scrollTo({ top: scrollY - 10 })
                }
                if (scrollY <= 0) {
                    b1.style.display = "none"
                    clearInterval(a);
                }
            }, 1)
        })


    </script>
</body>

</html>